package demo;

import org.junit.Test;

public class CropTest {

    //使用父类作为方法的返回值来实现多态
    public  Crop GetCrop(int type){
        Crop crop=null;
        switch (type){
            case 1:
                crop= new AppleTree("金帅");
                break;
            case 2:
                crop= new Corn(100);
                break;
            case 3:
                crop= new Pear("皇冠");
                break;
        }
        return  crop;
    }

    @Test
    public  void CropTest1(){
        Land land=new Land();
  /*      Crop pear=new Pear("皇冠");
        land.plant(pear);*/
        AppleTree appleTree=new AppleTree("金帅");
     /*   appleTree.printGrowReport(10);
        appleTree.harvest();*/
      /*  land.plant(appleTree);
        land.checkGrowReport(appleTree,10);*/
        Crop crop=new Corn(100);
        land.plant(crop);
        land.checkGrowReport(crop,10);
    }


    @Test
    public  void CropTest2(){
        Crop crop= GetCrop(2);
         crop.print();
    }



    @Test
    public  void CropTest3(){
     /*   Crop crop=new AppleTree("金帅");
        crop.print();
        if(crop instanceof  AppleTree){
            ((AppleTree)crop).grafting("红粉佳人");
        }
        crop.print();*/

        Crop crop=new AppleTree();
        AppleTree appleTree=(AppleTree) new Crop();
        appleTree.grafting("sdf");
        appleTree.print();
    }


    @Test
    public  void CropTest4(){
        Land land=new Land();
        Crop crop= new AppleTree();
        land.Call(crop);
    }

}
